package zuosheng.lianbiao;

import java.util.Stack;

/**
 * @author lj
 * @Description: 判断链表是否为回文
 * @date 2020-11-15 10:31
 * @QQ 851477108
 */


public class Palindrome {
    public class Node{
        public int value;
        public Node next;

        public Node(int data){
            this.value = data;
        }
    }

    //需要一个辅助栈
    public boolean isPalindrome1(Node head){
        Stack<Node> help = new Stack<>();
        Node cur = head;
        while (cur != null){
            help.push(cur);
            cur = cur.next;
        }

        while (head != null){
            if (head.value != help.pop().value){
                return false;
            }
            head = head.next;
        }
        return true;
    }
}
